from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication

from ..models import Token


class AuthClass(BaseAuthentication):
    def authenticate(self, request):
        try:
            print("auther is ok")
            token = request.COOKIES["token"]
            print(token)
            token = Token.objects.get(token=token)
            # print(token.user_id.name)
        except Exception as e:
            print(e)
            raise exceptions.AuthenticationFailed('认证失败')

        return token.employee, token.token

    def authenticate_header(self, request):
        pass
